#pragma once

#ifndef CONNECTIONTREEMODELH_H_
#define CONNECTIONTREEMODELH_H_

#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QAbstractItemModel>
#include <QtGui/QMessageBox>
#include <QtGui/QIcon>
#include <QtGui/QMenu>
#include "DBObject.h"
#include "DBConnection.h"

namespace SQLDoc
{
	class ConnectionTreeModel : public QAbstractItemModel
	{
		Q_OBJECT

	public:
		ConnectionTreeModel(QObject *parent = 0);
		~ConnectionTreeModel();

		void setRootItem(DBObject *item);

		/* BEGIN - MODEL/VIEW methods */
		QVariant data(const QModelIndex &index, int role) const;
		QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
		QModelIndex parent(const QModelIndex &index) const;
		int rowCount(const QModelIndex &parent = QModelIndex()) const;
		int columnCount(const QModelIndex &parent = QModelIndex()) const;
		bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const;
		QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
		bool canFetchMore(const QModelIndex& parent) const;
		void fetchMore(const QModelIndex& parent);
		virtual Qt::ItemFlags flags(const QModelIndex &index) const;
		virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
		/* END - MODEL/VIEW methods */

		DBObject *itemFromIndex(const QModelIndex &index) const;
		void addConnection(DBConnection* connection);

	private:
		DBObject *m_rootItem;
		QIcon *m_connectionIcon;
		QIcon *m_databaseIcon;
		QIcon *m_tableIcon;
	};

}

#endif
